Skip to content

Fix K8s executor pod_override stringified without cncf provider#67895

Merged
jscheffl merged 2 commits into
apache:mainfrom
astronomer:afl-32-decouple-v1pod-serialization
Jun 7, 2026
Merged

Fix K8s executor pod_override stringified without cncf provider#67895
jscheffl merged 2 commits into
apache:mainfrom
astronomer:afl-32-decouple-v1pod-serialization

Conversation

@ephraimbuddy
Copy link
Copy Markdown
Contributor

Airflow 3 deployments that run the Kubernetes executor with the kubernetes
package installed but without apache-airflow-providers-cncf-kubernetes
had their executor_config pod_override V1Pod silently converted to a
string during Dag serialization. The stringified pod was persisted to
serialized_dag._data and task_instance.executor_config, so affected tasks
stayed in queued and never ran. (Airflow 2 handled this case via an in-core
PodGenerator fallback that was removed ahead of the 3.0 release.)

Root cause

_has_kubernetes() in serialized_objects.py hardcoded an import of the cncf
provider's PodGenerator for V1Pod ser/deser. When that provider isn't
installed the import fails, _has_kubernetes() caches False, the V1Pod
serialization branch short-circuits, and default_serialization() falls back
to str(var).

Fix

Serialize/deserialize V1Pod objects directly through
kubernetes.client.ApiClient — which is all PodGenerator.serialize_pod and
PodGenerator.deserialize_model_dict wrap anyway — so airflow-core no longer
depends on any specific Kubernetes-executor provider. V1Pod ser/deser now
works with the cncf provider, an alternative executor package, or just the bare
kubernetes package installed. The backcompat unpickle path in
ensure_pod_is_valid_after_unpickling is decoupled the same way.

Tests

Added a regression test that makes apache-airflow-providers-cncf-kubernetes
unimportable and asserts V1Pod still round-trips through
BaseSerialization. The test blocks the ...pod_generator submodule directly
(not just the parent package) so it can't be fooled by import ordering when the
module is already cached by a sibling test. Existing K8s serialization tests
(test_serialize_v1pod_attempts_import_before_serializing, the
executor_config_pod fixtures, TestExecutorConfigType) continue to pass —
serialization output is byte-identical to the previous cncf-based path.


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Opus 4.8)

Generated-by: Claude Code (Opus 4.8) following the guidelines

Airflow 3 deployments using the Kubernetes executor with the `kubernetes`
package installed but without `apache-airflow-providers-cncf-kubernetes`
had their `executor_config` `pod_override` V1Pod silently converted to a
string during Dag serialization. The stringified pod was persisted to
`serialized_dag` and `task_instance.executor_config`, so affected tasks
stayed in `queued` and never ran.

`_has_kubernetes()` hardcoded an import of the cncf provider's
`PodGenerator` for V1Pod ser/deser. When only an alternative executor
package is installed, that import failed, `_has_kubernetes()` cached
False, and serialization fell back to `str(pod)`. Airflow 2 had an
in-core `PodGenerator` fallback for this case that was removed ahead of
the 3.0 release.

Serialize and deserialize V1Pod objects directly through
`kubernetes.client.ApiClient`, which is all `PodGenerator.serialize_pod`
and `deserialize_model_dict` wrap anyway. V1Pod ser/deser now works with
the cncf provider, an alternative executor package, or the bare
`kubernetes` package installed. The backcompat unpickle path in
`ensure_pod_is_valid_after_unpickling` is decoupled the same way.
@ephraimbuddy ephraimbuddy added the backport-to-v3-2-test Mark PR with this label to backport to v3-2-test branch label Jun 2, 2026
@ephraimbuddy ephraimbuddy added this to the Airflow 3.2.3 milestone Jun 2, 2026
@ephraimbuddy ephraimbuddy self-assigned this Jun 3, 2026
@ephraimbuddy ephraimbuddy requested review from Copilot and kaxil June 5, 2026 11:06
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes an Airflow 3 regression where Kubernetes executor executor_config["pod_override"] (kubernetes.client.models.V1Pod) could be silently stringified during DAG serialization when kubernetes is installed but apache-airflow-providers-cncf-kubernetes is not, causing queued tasks to never run. The change removes the hard dependency on the cncf provider’s PodGenerator by serializing/deserializing V1Pod directly via kubernetes.client.api_client.ApiClient.

Changes:

  • Replace cncf-provider PodGenerator usage with direct ApiClient-based V1Pod serialization/deserialization in BaseSerialization.
  • Decouple the backcompat unpickle repair path (ensure_pod_is_valid_after_unpickling) from the cncf provider.
  • Add a regression test that simulates the cncf provider being unimportable and asserts V1Pod still round-trips through BaseSerialization.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
airflow-core/src/airflow/serialization/serialized_objects.py Switch POD ser/deser from provider PodGenerator to direct kubernetes ApiClient, and update the missing-dependency error message.
airflow-core/src/airflow/utils/sqlalchemy.py Update the unpickling repair path to deserialize V1Pod via ApiClient rather than the cncf provider.
airflow-core/tests/unit/serialization/test_serialized_objects.py Update existing V1Pod import/patch test and add regression coverage for “no cncf provider installed”.

Comment thread airflow-core/src/airflow/serialization/serialized_objects.py
Comment thread airflow-core/src/airflow/utils/sqlalchemy.py
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@jscheffl jscheffl merged commit 4677e1e into apache:main Jun 7, 2026
79 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 7, 2026

Backport failed to create: v3-2-test. View the failure log Run details

Note: As of Merging PRs targeted for Airflow 3.X
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.

In matter of doubt please ask in #release-management Slack channel.

Status Branch Result
v3-2-test Commit Link

You can attempt to backport this manually by running:

cherry_picker 4677e1e v3-2-test

This should apply the commit to the v3-2-test branch and leave the commit in conflict state marking
the files that need manual conflict resolution.

After you have resolved the conflicts, you can continue the backport process by running:

cherry_picker --continue

If you don't have cherry-picker installed, see the installation guide.

jscheffl added a commit that referenced this pull request Jun 7, 2026
…ovider (#67895) (#68157)

* Fix Kubernetes executor pod_override stringified without cncf provider

Airflow 3 deployments using the Kubernetes executor with the `kubernetes`
package installed but without `apache-airflow-providers-cncf-kubernetes`
had their `executor_config` `pod_override` V1Pod silently converted to a
string during Dag serialization. The stringified pod was persisted to
`serialized_dag` and `task_instance.executor_config`, so affected tasks
stayed in `queued` and never ran.

`_has_kubernetes()` hardcoded an import of the cncf provider's
`PodGenerator` for V1Pod ser/deser. When only an alternative executor
package is installed, that import failed, `_has_kubernetes()` cached
False, and serialization fell back to `str(pod)`. Airflow 2 had an
in-core `PodGenerator` fallback for this case that was removed ahead of
the 3.0 release.

Serialize and deserialize V1Pod objects directly through
`kubernetes.client.ApiClient`, which is all `PodGenerator.serialize_pod`
and `deserialize_model_dict` wrap anyway. V1Pod ser/deser now works with
the cncf provider, an alternative executor package, or the bare
`kubernetes` package installed. The backcompat unpickle path in
`ensure_pod_is_valid_after_unpickling` is decoupled the same way.

* Apply suggestions from code review



---------
(cherry picked from commit 4677e1e)

Co-authored-by: Ephraim Anierobi <splendidzigy24@gmail.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:DAG-processing backport-to-v3-2-test Mark PR with this label to backport to v3-2-test branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants